<?php

namespace app\common\model\mysql;

use think\Model;

class Reimburse extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'acc_reimburse';

    /**
     * 新增报销数据
     * @param $data
     * @return mixed
     * @throws \think\Exception
     */
    public function addReimburseData($data){
        $this->save($data);
        return $this->id;
    }

    /**
     * 根据where条件获取报销分页数据
     * @param $where
     * @param $limit
     * @param $page
     * @param $field
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function getNormalReimburseList($where,$limit,$page,$field){
        $order = [
            "a.applydate"=>"desc"
        ];
        $result = $this->alias('a')->join('wo_worker b', 'a.worker_id_apply = b.worker_id')->where($where)->field($field)->order($order)
            ->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
        return $result->toArray();
    }

    /**
     * 根据where条件获取报销分页数据
     * @param $where
     * @param $limit
     * @param $page
     * @param $field
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function getNormalReimburseFind($where,$field){
        $result = $this->alias('a')->join('wo_worker b', 'a.worker_id_apply = b.worker_id')->where($where)->field($field)->find();
        return $result ? $result->toArray() : [];
    }
}
